package com.test.multithread.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

/**
 * Druid连接池的使用
 */
public class Druiddemo {
    Connection conn=null;
    PreparedStatement prep=null;
    ResultSet rs=null;

    @Test
    public void test() throws Exception {
        //从druid.properties中读取数据
        Properties properties=new Properties();
        properties.load(new FileInputStream("D:\\zkt_project\\nest-platform\\study-juc\\src\\main\\resources\\druid.properties"));
        DataSource dataSource= DruidDataSourceFactory.createDataSource(properties);
        conn=dataSource.getConnection();
        prep=conn.prepareStatement("select * from user");
        rs=prep.executeQuery();
        while (rs.next()){
            System.out.println(rs.getString("uid"));
            System.out.println(rs.getString("user_name"));
        }
        JDBCUtils.release(rs,prep,conn);
    }
}

